package com.gx.ring.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.gx.ring.dao.RingExistCorpIDInterfaceDAO;
import com.gx.ring.entity.PersonalLib;

public class PLInterfaceImplDAO implements RingExistCorpIDInterfaceDAO<PersonalLib>{
	private Connection conn = null;
	
	public PLInterfaceImplDAO(Connection conn) {
		this.conn = conn;
	}
	@Override
	public List<PersonalLib> queryByphNumber(String phNumber) throws SQLException {
		String sql = "SELECT * FROM ring.t_personallib WHERE PHONENUMBER=? ";
		List<PersonalLib> ls = new ArrayList<>();
		PersonalLib plb = new PersonalLib();
		PreparedStatement pst = conn.prepareStatement(sql);
		pst.setString(1, phNumber);
		ResultSet rs = pst.executeQuery();
		while(rs.next()){
			plb = saveResult(rs);
			ls.add(plb);
		}
		rs.close();
		pst.close();
		return ls;
	}

	@Override
	public List<PersonalLib> queryByCorpCode(String corpCode) throws SQLException {
		String sql = "SELECT * FROM ring.t_personallib WHERE CORPCODE=? ";
		List<PersonalLib> ls = new ArrayList<>();
		PersonalLib plb = new PersonalLib();
		PreparedStatement pst = conn.prepareStatement(sql);
		pst.setString(1, corpCode);
		ResultSet rs = pst.executeQuery();
		while(rs.next()){
			plb = saveResult(rs);
			ls.add(plb);
		}
		rs.close();
		pst.close();
		return ls;
	}
	
	@Override
	public PersonalLib saveResult(ResultSet rs) throws SQLException {
		PersonalLib plb = new PersonalLib();
		plb.setBindflag(rs.getLong("BINDFLAG"));
		plb.setChannelplayerid(rs.getString("CHANNELPLAYERID"));
		plb.setChargetype(rs.getLong("CHARGETYPE"));
		plb.setCorpcode(rs.getString("CORPCODE"));
		plb.setCorpid(rs.getLong("CORPID"));
		plb.setCorpname(rs.getString("CORPNAME"));
		plb.setDiyuserphone(rs.getString("DIYUSERPHONE"));
		plb.setDownflag(rs.getLong("DOWNFLAG"));
		plb.setDowntime(rs.getTimestamp("DOWNTIME"));
		plb.setEnableddate(rs.getTimestamp("ENABLEDDATE"));
		plb.setExpireddealflag(rs.getLong("EXPIREDDEALFLAG"));
		plb.setFreeenddate(rs.getTimestamp("FREEENDDATE"));
		plb.setIntegralflag(rs.getLong("INTEGRALFLAG"));
		plb.setIsexperience(rs.getLong("ISEXPERIENCE"));
		plb.setLanguagename(rs.getString("LANGUAGENAME"));
		plb.setModulecode(rs.getString("MODULECODE"));
		plb.setMonthprice(rs.getLong("MONTHPRICE"));
		plb.setMusicid(rs.getString("MUSICID"));
		plb.setOperator(rs.getLong("OPERATOR"));
		plb.setOrderinterfaceprice(rs.getLong("ORDERINTERFACEPRICE"));
		plb.setPersontoneid(rs.getLong("PERSONTONEID"));
		plb.setPhonenumber(rs.getString("PHONENUMBER"));
		plb.setPrice(rs.getLong(rs.getString("TPRICE")));
		plb.setProductid(rs.getString("PRODUCTID"));
		plb.setRelativetime(rs.getTimestamp("RELATIVETIME"));
		plb.setResourceid(rs.getLong("RESOURCEID"));
		plb.setResourcetype(rs.getLong("RESOURCETYPE"));
		plb.setSinger(rs.getString("SINGER"));
		plb.setSingerletter(rs.getString("SINGERLETTER"));
		plb.setSingersex(rs.getLong("SINGERSEX"));
		plb.setSpcode(rs.getString("SPCODE"));
		plb.setSpid(rs.getLong("SPID"));
		plb.setSpname(rs.getString("SPNAME"));
		plb.setStatus(rs.getLong("STATUS"));
		plb.setSubscribetype(rs.getLong("SUBSCRIBETYPE"));
		plb.setSystemid(rs.getString("SYSTEMID"));
		plb.setTonecode(rs.getString("TONECODE"));
		plb.setToneinfo(rs.getString("TONEINFO"));
		plb.setTonelanguage(rs.getLong("TONELANGUAGE"));
		plb.setTonename(rs.getString("TONENAME"));
		plb.setTonenameletter(rs.getString("TONENAMELETTER"));
		plb.setTotalprice(rs.getLong("TOTALPRICE"));
		plb.setTryenddate(rs.getTimestamp("TRYENDDATE"));
		plb.setUpdatetime(rs.getTimestamp("UPDATETIME"));
		plb.setUploadtime(rs.getTimestamp("UPLOADTIME"));
		plb.setVacspid(rs.getString("VACSPID"));
		plb.setValiddate(rs.getTimestamp("VALIDDATE"));
		return null;
	}



}
